from selenium.webdriver.common.by import By

from pom.base import BaseDriver

class RigthManagePage(BaseDriver):
    def __init__(self, driver):
        super(RigthManagePage, self).__init__(driver)

    # 搜索框
    _search_box = (By.XPATH, '//input[@placeholder="请输入用户名称/角色"]')

    # 搜索按钮
    _search_button = (By.XPATH, '//span[text()="搜索"]/..')

    # 新增按钮
    _create_button = (By.XPATH, '//button/span[text()="新增"]')

    # 导入按钮
    _import_buuton = By.XPATH, '//span[text()="导入"]'

    # 编辑操作
    _edit = By.XPATH, '//span[text()="编辑"]/..'
    # 禁用操作
    _disabled = By.XPATH, '//span[text()="禁用"]/..'

    """
    用户编辑框
    """
    # 用户名
    _edit_username = By.XPATH, '//input[@placeholder="请输入用户名"]'

    # 登录名称
    _login_name = By.XPATH, '//input[@placeholder="请输入登录名"]'

    # 新密码
    _new_passwd = By.XPATH, '//label[text()="新密码"]//following-sibling::div[1]/div/input'
    # _new_passwd = By.XPATH, '//input[@placeholder="密码长度大于8位，大写字母、小写字母、数字和特殊字符包含任意1种"]'

    # 确认新密码
    _confirm_passwd = By.XPATH, '//input[@placeholder="请确认新密码"]'

    # 部门
    _department = By.XPATH, '//input[@placeholder="请输入部门"]'

    # 删除
    _delete_btn = By.XPATH, '//span[text()="删除"]/..'

    # 取消
    _cancel_btn = By.XPATH, '//div[@class="f-tar"]//span[text()="取消"]/..'

    # 确定
    _comit_btn = By.XPATH, '//div[@class="f-tar"]//span[text()="确定"]/..'

    @property
    def comit_btn(self):
        ele = self.find_ele(*self._comit_btn)
        self.logger.info("权限管理-用户编辑 [确定] 按钮")
        return ele

    @property
    def cancel_btn(self):
        ele = self.find_ele(*self._cancel_btn)
        self.logger.info("权限管理-用户编辑 [取消] 按钮")
        return ele

    @property
    def delete_btn(self):
        ele = self.find_ele(*self._delete_btn)
        self.logger.info("权限管理-用户编辑 [删除] 按钮")
        return ele

    @property
    def login_name(self):
        ele = self.find_ele(*self._login_name)
        self.logger.info("权限管理-用户编辑 [登录名] 输入框")
        return ele

    @property
    def department(self):
        ele = self.find_ele(*self._department)
        self.logger.info("权限管理-用户编辑 [部门] 输入框")
        return ele

    @property
    def confirm_passwd(self):
        ele = self.find_ele(*self._confirm_passwd)
        self.logger.info("权限管理-用户编辑 [确认密码] 输入框")
        return ele

    @property
    def new_passwd(self):
        ele = self.find_ele(*self._new_passwd)
        self.logger.info("权限管理-用户编辑 [新密码] 输入框")
        return ele

    @property
    def edit_username(self):
        ele = self.find_ele(*self._edit_username)
        self.logger.info("权限管理-编辑用户 [用户名] 输入框")
        return ele

    @property
    def edit(self):
        ele = self.find_ele(*self._edit)
        self.logger.info("权限管理 [编辑] 按钮")
        return ele

    @property
    def disabled(self):
        ele = self.find_ele(*self._disabled)
        self.logger.info("权限管理 [禁用] 按钮")
        return ele

    @property
    def search_box(self):
        ele = self.find_ele(*self._search_box)
        self.logger.info("权限管理 [搜索] 输入框")
        return ele

    # 人员列表也可用做搜索后的结果查看，可能会有多条数据，返回列表

    def list_num(self):
        eles = self.find_eles(By.XPATH, '//tr[@class="el-table__row"]')
        self.logger.info("权限管理 [搜索后的人员列表]")
        return eles

    # 人员列表的第line行 第 col 列的数据是什么
    def person_list(self, line, col):
        """:arg
        col
        1 序号
        2 用户名称
        3 登录名称
        4 用户角色
        5 单位
        6 来源（用户中心、系统导入）
        7 操作
        """
        ele = self.find_ele(By.XPATH, '//tr[@class="el-table__row"][{}]/td[@class="el-table_1_column_{}  "]'.format(line, col))
        return ele.text

    @property
    def search_button(self):
        ele = self.find_ele(*self._search_button)
        self.logger.info("权限管理 [搜索] 按钮")
        return ele


